From 5a5a36151a867ce8761fef392a2526cc0fd96a16 Mon Sep 17 00:00:00 2001 From: robxnano <91250-robxnano@users.noreply.gitlab.gnome.org> Date: Tue, 28 Feb 2023 22:50:56 +0000 Subject: [PATCH] filechooser: Don't automatically select a file When the folder changes, do not select the first item in the list, so if the user enters a folder and then clicks the accept button, the current folder is returned instead of the selected one. To maintain consistency with the previous implementation, when a folder in the path bar is clicked the previously-entered folder is selected, and when the file chooser is in open file mode the first item is always selected. See #5438 --- gtk/gtkfilechooserwidget.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 70276967e5..5653ae7a3d 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -2571,7 +2571,11 @@ set_select_multiple (GtkFileChooserWidget *impl, if (select_multiple) impl->selection_model = GTK_SELECTION_MODEL (gtk_multi_selection_new (model)); else - impl->selection_model = GTK_SELECTION_MODEL (gtk_single_selection_new (model)); + { + impl->selection_model = GTK_SELECTION_MODEL (gtk_single_selection_new (model)); + gtk_single_selection_set_can_unselect (GTK_SINGLE_SELECTION (impl->selection_model), TRUE); + gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (impl->selection_model), FALSE); + } g_signal_connect (impl->selection_model, "selection-changed", G_CALLBACK (list_selection_changed), impl); @@ -7289,6 +7293,9 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl) G_CALLBACK (list_items_changed), impl); gtk_single_selection_set_model (GTK_SINGLE_SELECTION (impl->selection_model), G_LIST_MODEL (impl->sort_model)); + gtk_single_selection_set_can_unselect (GTK_SINGLE_SELECTION (impl->selection_model), TRUE); + gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (impl->selection_model), FALSE); + gtk_sort_list_model_set_model (impl->sort_model, G_LIST_MODEL (impl->filter_model)); gtk_column_view_set_model (GTK_COLUMN_VIEW (impl->browse_files_column_view), impl->selection_model); -- 2.30.2